import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { getWeekMonthQuarterYear } from '/@/utils';
const categoryOptions = [
  {
    id: '1',
    label: '党务政务',
    value: '1',
    key: '1',
  },
  {
    id: '2',
    label: '廉政建设',
    value: '2',
    key: '2',
  }];

const typeOptionsData = {
  dwzw: [
    {
      label: '党政建设',
      value: '1',
      key: '1',
    }
  ],
  lzjs: [
    {
      label: '廉政制度',
      value: '2',
      key: '2',
    },
    {
      label: '廉政文化',
      value: '3',
      key: '3',
    },
    {
      label: '廉政教育',
      value: '4',
      key: '4',
    },
  ],
};
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '党政建设分类',
    align: "center",
    dataIndex: 'category_dictText'
  },
  {
    title: '细分类型',
    align: "center",
    dataIndex: 'type_dictText'
  },
  {
    title: '标题',
    align: "center",
    dataIndex: 'titile'
  },
  {
    title: '摘要',
    align: "center",
    dataIndex: 'summary'
  },

  {
    title: '优先级',
    align: "center",
    dataIndex: 'priority_dictText'
  },
  {
    title: '发布状态',
    align: "center",
    dataIndex: 'publishStatus_dictText'
  },
  {
    title: '发布人',
    align: "center",
    dataIndex: 'publisher'
  },
  {
    title: '发布时间',
    align: "center",
    dataIndex: 'publishTime',
	customRender:({text}) =>{
	  text = !text ? "" : (text.length > 10 ? text.substr(0,10) : text);
	  return text;
	},
  },

];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: "分类",
    field: 'category',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: "party_category"
    },
    //colProps: {span: 6},
  },
  {
    label: "标题",
    field: 'titile',
    component: 'Input',
    //colProps: {span: 6},
  },
  {
    label: "发布状态",
    field: 'publishStatus',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: "web_publish_status"
    },
    //colProps: {span: 6},
  },
  {
  	 label: "发布时间",
  	 field: "publishTime",
  	 component: 'RangePicker',
  	 componentProps: {
  	     valueType: 'Date',
  	     showTime:true
  	 },
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '党政建设分类',
    field: 'category',
    component: 'Select',
    // componentProps:{
    //     dictCode:"party_category",
    componentProps: ({ formModel, formActionType }) => {
      return {
        options: categoryOptions,
        onChange: function (e: any) {
          console.log(e)
          let citiesOptions = e == 1 ? typeOptionsData["dwzw"] : typeOptionsData['lzjs'];
          // console.log(citiesOptions)
          if (e === undefined) {
            citiesOptions = [];
          }
          formModel.type = undefined; //  reset city value
          const { updateSchema } = formActionType;
          updateSchema({
            field: 'type',
            componentProps: {
              options: citiesOptions,
            },
          });
        }
      }
    },
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请选择分类' },
      ];
    },
  },
  {
    label: '细分类型',
    field: 'type',
    component: 'Select',
     componentProps: {
      options: [], // defalut [] 
    },
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入细分类型!' },
      ];
    },
  },
  {
    label: '标题',
    field: 'titile',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入标题!' },
      ];
    },
  },
  {
    label: '摘要',
    field: 'summary',
    component: 'InputTextArea',
  },
  {
    label: '内容',
    field: 'content',
    component: 'JEditor',
  },
  {
    label: '优先级',
    field: 'priority',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: "priority_type"
    },
	dynamicRules: ({ model, schema }) => {
	  return [
	    { required: true, message: '请选择优先级!' },
	  ];
	},
  },
  {
    label: '发布状态',
    field: 'publishStatus',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: "web_publish_status"
    },
	dynamicRules: ({ model, schema }) => {
	  return [
	    { required: true, message: '请选择发布状态!' },
	  ];
	},
  },
  {
    label: '发布人',
    field: 'publisher',
    component: 'Input',
  	dynamicRules: ({model,schema}) => {
  	      return [
  	             { required: true, message: '请输入发布人!'},
  	      ];
  	 },
  },
  {
    label: "发布时间",
    field: "publishTime",
    component: 'DatePicker',
    componentProps: {
  		showTime: true,
        valueFormat :'YYYY-MM-DD HH:mm:ss'
    },
  	dynamicRules: ({model,schema}) => {
  	      return [
  	             { required: true, message: '请输入发布时间!'},
  	      ];
  	 },
    //colProps: {span: 6},
  },


  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false
  },
];

// 高级查询数据
export const superQuerySchema = {
  category: { title: '分类1:党务政务2:廉政建设', order: 0, view: 'list', type: 'string', dictCode: 'party_category', },
  type: { title: '细分类型（1-1:党政建设）（2-1:廉政制度，2-2:廉政文化，2-3:廉政教育）', order: 1, view: 'list', type: 'string', },
  titile: { title: '标题', order: 2, view: 'text', type: 'string', },
  summary: { title: '摘要', order: 3, view: 'text', type: 'string', },
  content: { title: '内容', order: 4, view: 'textarea', type: 'string', },
  priority: { title: '优先级（L低，M中，H高）', order: 5, view: 'list', type: 'string', dictCode: 'priority_type', },
  publishStatus: { title: '发布状态（0未发布，1已发布，2已撤销）', order: 6, view: 'list', type: 'string', dictCode: 'web_publish_status', },
  publisher: { title: '发布人', order: 7, view: 'text', type: 'string', },
  publishTime: { title: '发布时间', order: 8, view: 'datetime', type: 'string', },
  readNum: { title: '浏览量', order: 10, view: 'text', type: 'string', },
};

/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
